﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//最近更新: 2016/8/24
//功能说明：用户信息维护
//********************************************************************************//
using System;
using System.Web.UI;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.YongHuGL
{
    /// <summary>
    /// 用户信息维护
    /// </summary>
    public partial class YongHuXXWH : BasePage
    {
        #region 属性

        /// <summary>
        /// gridView主键(用户信息ID)
        /// </summary>
        private int YONGHUXXID
        {
            get
            {
                return Convert.ToInt32(ViewState["_YONGHUXXID"]);
            }
            set
            {
                ViewState["_YONGHUXXID"] = value;
            }
        }

        /// <summary>
        /// 记录合同号
        /// </summary>
        private string HETONGH
        {
            get
            {
                return Convert.ToString(ViewState["HETONGH"]);
            }
            set
            {
                ViewState["HETONGH"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 用户信息对象
        /// </summary>
        YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
                InitData();
                Display();
            }
        }

        /// <summary>
        /// 重写Render方法
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// 查询管理块
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.cmbConGuanLiK.Text == ""&&this.txtConYongHuH.Text=="")
            {
                return;
            }
            if(this.txtConYongHuH.Text.Trim()=="")
            {
                return;
            }
            this.Status = GridViewStatus.Init;
            this.InitData();
            //查询 
            DataTable dt = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("I_JLZT=0 and {0} and {1} and i_leixing=1", this.cmbConGuanLiK.Text.ToString() == "" ? "S_ZHANDIANBH='" + BusinessTool.ZHANDIANBH() + "'" : "S_GUANLIKBH='" + this.cmbConGuanLiK.Value.ToString() + "'", " S_YONGHUH='" + this.txtConYongHuH.Text.Trim() + "'"), null);
            if (dt.Rows.Count == 0)
            {
                this.YONGHUXXID = -1;
                PageTools.AlertMsg(this, "该用户不存在,请重新输入！");
                return;
            }
            this.YONGHUXXID = Convert.ToInt32(dt.Rows[0]["ID"]);
            string zhandianbh=dt.Rows[0]["S_ZHANDIANBH"].ToString();
            //查询当前查询出的用户站点 
            dt = new YS_JX_ZHANDIANBLL().SelectYS_JX_ZHANDIANsDynamic("S_ZHANDIANBH='" + zhandianbh + "'",null);
            if (dt.Rows.Count == 1)
            {
                this.txtZhanDian.Text = dt.Rows[0]["S_ZHANDIANBH"] + "-" + dt.Rows[0]["S_ZHANDIANMC"];
            }
            else
            {
                this.txtZhanDian.Text = "该用户站点在系统中不存在，请检查数据。";
            }
            //根据当前查询用户加载用水性质
            PageTools.LoadComboxYongShuiXZByGuanLiK(this.cmbYongShuiXZ,this.txtConYongHuH.Text.Substring(0,2),null,null);
            this.Status = GridViewStatus.Search;
            Display();
            SetData();
        }

        /// <summary>
        /// grid添加
        /// </summary>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //初始化数据
            InitData();
            this.Status = GridViewStatus.Add;
            Display();
        }

        /// <summary>
        /// grid放弃
        /// </summary>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.Status = GridViewStatus.Init;
            Display();
            //如果当前有操作项 重新加载数据
            if(this.YONGHUXXID>0)
            {
                SetData();
            }
        }

        /// <summary>
        /// 修改gridview
        /// </summary>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            this.Status = GridViewStatus.Update;
            //记忆当前修改的ID
            Display();
        }

        /// <summary>
        /// grid保存
        /// </summary>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                SaveData();
            }    
        }

        /// <summary>
        /// 用水性质变更显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbYongShuiXZ_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            PageTools.LoadComboxYongShuiXZByGuanLiK(this.cmbYongShuiXZ, this.cmbGuanLiK.Value.ToString(),"-", null);
        }


        protected void cmbGongSi_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            PageTools.LoadComboxGongSi((DevExpress.Web.ASPxComboBox)sender, Convert.ToString(this.cmbJu.Value), null);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            if (e.Parameter == "gethth")
            {
                cr.SpecialIndetity = BusinessTool.GetHeTongH(this.txtYongHuH.Text);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                e.Result = cr.ToString();
                return;
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {           
            //加载条件查询处的管理块
            PageTools.LoadCombox(this.cmbConGuanLiK, PageTools.eLoadType.管理块, BusinessTool.ZHANDIANBH(), null, "");
            PageTools.LoadCombox(this.cmbGuanLiK, PageTools.eLoadType.管理块, BusinessTool.ZHANDIANBH(), null,null);
            if (this.cmbGuanLiK.Items.Count != 0)
            {
                this.txtGuanLiK.Text = this.cmbGuanLiK.Value.ToString();
            }
            //加载行政区
            PageTools.LoadCombox(this.cmbXingZhengQ, PageTools.eLoadType.行政区, BusinessTool.ZHANDIANBH(), null, null);
            this.txtXingZhengQ.Text = this.cmbXingZhengQ.Value.ToString();
            //加载局
            //操作员站点为本部时 加载局信息
            if (BusinessTool.ZHANDIANBH() == "51" || BusinessTool.ZHANDIANBH() == "00")
            {
                PageTools.LoadCombox(this.cmbJu,PageTools.eLoadType.局,null,null,null);
                if (this.cmbJu.Items.Count > 0)
                {
                    this.cmbJu.SelectedIndex = 0;
                    this.txtJu.Text = this.cmbJu.Value.ToString();
                    PageTools.LoadComboxGongSi((DevExpress.Web.ASPxComboBox)this.cmbGongSi, Convert.ToString(this.cmbJu.Value), null);
                }
            }
            else
            {
                this.cmbJu.ClientEnabled = false;
                this.cmbGongSi.ClientEnabled = false;
            }
            //加载业务员
            PageTools.LoadCombox(this.cmbYeWuY, PageTools.eLoadType.业务员, false, null, null);
            if (this.cmbYeWuY.Items.Count != 0)
            {
                this.txtYeWuY.Text = this.cmbYeWuY.Value.ToString();
            }
            //加载用水性质
            PageTools.LoadComboxYongShuiXZByGuanLiK(this.cmbYongShuiXZ, Convert.ToString(this.cmbGuanLiK.Value),"-", null);
            
            //加载考核复用
            WordsManager manger = new WordsManager();
            PageTools.BindComboBox(this.cmbKaoHeFY, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.考核复用, "-"));
            if (this.cmbKaoHeFY.Items.Count != 0)
            {
                this.cmbKaoHeFY.SelectedIndex = 0;
            }
            //加载证件类型
            PageTools.BindComboBox(this.cmbZhengJianLX, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.证件号类型, "-"));
            if (this.cmbZhengJianLX.Items.Count != 0)
            {
                this.cmbZhengJianLX.SelectedIndex = 0;
            }
            //加载代码类型
            PageTools.BindComboBox(this.cmbDaiMaLX, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.代码类型, "-"));
            if (this.cmbDaiMaLX.Items.Count != 0)
            {
                this.cmbDaiMaLX.SelectedIndex = 0;
            }
            //加载涉水对象代码
            PageTools.BindComboBox(
                 this.cmbSheShuiDXDM, BusinessTool.GetTextAndValue(
                 "YS_JX_HANGYELX", "S_SHESHUIDXFLMC", "S_SHESHUIDXFLDM", "-", null
                 ).Tables[0]
             );
            if (this.cmbSheShuiDXDM.Items.Count != 0)
            {
                this.cmbSheShuiDXDM.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            this.txtGongSi.Text = "";
            this.txtHuiGuanSBS.Text = "";
            this.txtHeTongH.Text = "";
            this.txtLianXiBM.Text = "";
            this.txtLianXiDH.Text = "";
            this.txtLianXiR.Text = "";
            this.txtShiKaoHY.Text = "";
            this.txtYHZH.Text = "";
            this.txtYongHuDZ.Text = "";
            this.txtYongHuH.Text = "";
            this.txtYONGHUM.Text = "";
            this.txtYouBian.Text = "";
            this.txtYSJ.Text = "";

            this.txtGuanLiK.Text = "";
            this.txtXingZhengQ.Text = "";
            this.txtJu.Text = "";
            this.txtGongSi.Text = "";
            this.txtYeWuY.Text = "";
            this.txtFaRen.Text = "";
            this.txtZhengJianH.Text = "";
            this.txtDaiMa.Text = "";

            this.cmbGongSi.Value = "";
            this.cmbGuanLiK.Value = "";
            this.cmbJu.Value = "";
            this.cmbKaoHeFY.Value = "";
            this.cmbSheShuiDXDM.Value = "";
            this.cmbXingZhengQ.Value = "";
            this.cmbYeWuY.Value = "";
            this.cmbYongShuiXZ.Value = "";
            this.cmbZhengJianLX.Value = "";
            this.cmbDaiMaLX.Value = "";
            
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
        }

        /// <summary>
        ///用于控制添加、修改、查看三种状态的显示
        /// </summary>
        private void Display()
        {
            switch (this.Status)
            {
                case GridViewStatus.Init:
                    btnEdit.Visible = true;
                    btnEdit.Enabled = false;
                    btnSave.Visible = false;
                    btnCancel.Visible = false;
                    InitData();
                    SetText(false);
                    break;
                case GridViewStatus.Search:
                    btnEdit.Visible = true;
                    btnEdit.Enabled = true;
                    btnSave.Visible = false;
                    btnCancel.Visible = false;
                    SetText(false);
                    break;
                case GridViewStatus.Update:
                    btnEdit.Visible = false;
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                    SetText(true);
                    this.txtYongHuH.Enabled = false;
                    this.cmbGuanLiK.Focus();
                    break;
                case GridViewStatus.Add:
                    btnEdit.Visible = false;
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                    SetText(true);
                    break;
            }
        }


        /// <summary>
        /// 设置输入框状态
        /// </summary>
        /// <param name="b"></param>
        private void SetText(bool b)
        {
            this.txtYongHuH.ClientEnabled = false;
            this.txtYHZH.ClientEnabled = b;
            this.txtYongHuDZ.ClientEnabled = b;
            this.txtYONGHUM.ClientEnabled = b;
            this.txtYouBian.ClientEnabled = b;
            this.txtBeiZhu.ClientEnabled = b;
            this.txtKaiHuHM.ClientEnabled = b;
            this.txtKaiHuYH.ClientEnabled = b;
            this.txtLianXiBM.ClientEnabled = b;
            this.txtLianXiDH.ClientEnabled = b;
            this.txtLianXiR.ClientEnabled = b;
            this.txtYouBian.ClientEnabled = b;            
            this.cmbGongSi.ClientEnabled = b;
            this.cmbJu.ClientEnabled = b;
            this.cmbKaoHeFY.ClientEnabled = b;
            this.cmbSheShuiDXDM.ClientEnabled = btnDinge.ClientEnabled = b;
            this.cmbXingZhengQ.ClientEnabled = b;
            this.cmbYeWuY.ClientEnabled = b;
            this.cmbYongShuiXZ.ClientEnabled = b;
            this.txtHeTongH.ClientEnabled = b;
            this.cmbGuanLiK.ClientEnabled = b;
            this.cbChengNuo.ClientEnabled = b;
            this.cbTuoShou.ClientEnabled = b;
            this.txtFaRen.ClientEnabled = b;
            this.cmbZhengJianLX.ClientEnabled = b;
            this.txtZhengJianH.ClientEnabled = b;
            this.cmbDaiMaLX.ClientEnabled = b;
            this.txtDaiMa.ClientEnabled = b;
            this.txtZhanDian.ClientEnabled = false;
            this.txtGuanLiK.ClientEnabled = false;
            this.txtXingZhengQ.ClientEnabled = false;
            this.txtJu.ClientEnabled = false;
            this.txtGongSi.ClientEnabled = false;
            this.txtYeWuY.ClientEnabled = false;
            this.txtZiLaiSBS.ClientEnabled = false;
            this.txtHuiGuanSBS.ClientEnabled = false;
            this.txtShiKaoHY.ClientEnabled = false;
            
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        private void SaveData()
        {
            OperateState operateState;
            //修改操作
            operateState = OperateState.Modify;
            //判断是否修改了银行信息            
            //记录ID 只是用于记录修改日志
            this._YS_YG_YONGHUXX = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXX(this.YONGHUXXID);
            this._YS_YG_YONGHUXX.S_YONGHUH = this.txtYongHuH.Text;
            
            
            this._YS_YG_YONGHUXX.S_BEIZHU = this.txtBeiZhu.Text;
            this._YS_YG_YONGHUXX.I_KAOHEFY = Convert.ToDecimal(this.cmbKaoHeFY.Value);
            this._YS_YG_YONGHUXX.I_SHIKAOHY = this.txtShiKaoHY.Text == ""?0:Convert.ToInt32(this.txtShiKaoHY.Text);
            this._YS_YG_YONGHUXX.I_YONGHUZT = 0;
            this._YS_YG_YONGHUXX.N_YSJ = this.txtYSJ.Text != "" ? Convert.ToDouble(this.txtYSJ.Text):0;            
            this._YS_YG_YONGHUXX.S_DIZHI = this.txtYongHuDZ.Text;
            if (Convert.ToString(this.cmbGongSi.Value) != "")
            {
                this._YS_YG_YONGHUXX.S_GONGSIBH = Convert.ToString(this.cmbGongSi.Value);
            }
            this._YS_YG_YONGHUXX.S_GUANLIKBH = this.cmbGuanLiK.Value.ToString();
            if (Convert.ToString(this.cmbJu.Value)!="")
            {
                this._YS_YG_YONGHUXX.S_JUBIANH = Convert.ToString(this.cmbJu.Value);
            }
            this._YS_YG_YONGHUXX.S_KAIHUHM = this.txtKaiHuHM.Text;
            this._YS_YG_YONGHUXX.S_KAIHUYH = this.txtKaiHuYH.Text;
            this._YS_YG_YONGHUXX.S_LIANXIBM = this.txtLianXiBM.Text;
            this._YS_YG_YONGHUXX.S_LIANXIDH = this.txtLianXiDH.Text;
            this._YS_YG_YONGHUXX.S_LIANXIR = this.txtLianXiR.Text;
            this._YS_YG_YONGHUXX.S_SHESHUIDXDM = Convert.ToString(this.cmbSheShuiDXDM.Value);
            this._YS_YG_YONGHUXX.S_XINGZHENGQBH = Convert.ToString(this.cmbXingZhengQ.Value);
            this._YS_YG_YONGHUXX.S_YEWUY = Convert.ToString(this.cmbYeWuY.Value);
            this._YS_YG_YONGHUXX.S_YINHANGZH = this.txtYHZH.Text;
            this._YS_YG_YONGHUXX.S_YONGHUH = this.txtYongHuH.Text;
            this._YS_YG_YONGHUXX.S_YONGHUM = this.txtYONGHUM.Text;
            this._YS_YG_YONGHUXX.S_YONGSHUIXZ = Convert.ToString(this.cmbYongShuiXZ.Value);
            this._YS_YG_YONGHUXX.S_YOUBIAN = this.txtYouBian.Text;
            //this._YS_YG_YONGHUXX.S_ZHANDIANBH = this.txtZhanDian.Text.Substring(0, 2);//不用更新站点
            this._YS_YG_YONGHUXX.I_SHOUFEIFS = this.cbTuoShou.Checked ? 1 : 0;
            this._YS_YG_YONGHUXX.I_CHENNUOFF = this.cbChengNuo.Checked ? 1 : 0;
            this._YS_YG_YONGHUXX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            this._YS_YG_YONGHUXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            this._YS_YG_YONGHUXX.D_XIUGAIRQ = this._YS_YG_YONGHUXX.D_CAOZUOSJ;
            //其他信息
            string fieldList,queren,rsno,rsmsg;
            _YS_YG_YONGHUXXBLL.UpdateYS_YG_YONGHUXX(_YS_YG_YONGHUXX,null,out fieldList,out queren,out rsno,out rsmsg);
            if(rsno=="1")
            {
                _SYS_LOGBLL.Log<YS_YG_YONGHUXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "用户管理-用户信息维护", operateState, _YS_YG_YONGHUXX, null);
                //执行用户信息维护同步
                _spHelper.P_YS_YONGHUXXWEIHUTB(this._YS_YG_YONGHUXX.S_YONGHUH, null,int.Parse(queren), LoginInfo.CurrentUser.UserID.ToString(), fieldList.ToString());
                //更新银行批量代理合同号
                _spHelper.P_YS_YINHANGPLDLHTHXG(this._YS_YG_YONGHUXX.S_YONGHUH, this.txtHeTongH.Text);
                //更新证件号机构代码等
                string faren = this.txtFaRen.Text.Trim() == "" ? null : this.txtFaRen.Text;
                int? zhengjianlx = this.cmbZhengJianLX.Value == null ? null : (int?)Convert.ToInt32(this.cmbZhengJianLX.Value);
                string zhengjianh = this.txtZhengJianH.Text.Trim() == "" ? null : this.txtZhengJianH.Text.Trim();
                int? daimalx = this.cmbDaiMaLX.Value == null ? null : (int?)Convert.ToInt32(this.cmbDaiMaLX.Value);
                string daima = this.txtDaiMa.Text.Trim() == "" ? null : this.txtDaiMa.Text.Trim();              
                _spHelper.P_YSYG_UPDATEEXTENDINFO(this._YS_YG_YONGHUXX.S_YONGHUH, LoginInfo.CurrentUser.UserID, faren, zhengjianlx, zhengjianh, daimalx, daima, out rsno, out rsmsg);
                if (rsno == "-1")
                {
                    PageTools.AlertMsg(this, rsmsg);
                }
                else
                {
                    PageTools.AlertMsg(this, "保存成功！");
                }
                this.Status = GridViewStatus.Search;
                Display();
            }
            else
            {
                PageTools.AlertMsg(this, "保存失败！");
            }
        }

        /// <summary>
        /// 给输入框赋值
        /// </summary>
        private void SetData()
        {
            _YS_YG_YONGHUXX = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXX(this.YONGHUXXID, null);
            this.txtBeiZhu.Text = this._YS_YG_YONGHUXX.S_BEIZHU;
            this.txtHeTongH.Text = BusinessTool.GetHeTongH(_YS_YG_YONGHUXX.S_YONGHUH);
            //设置用户信息
            this.txtKaiHuHM.Text = this._YS_YG_YONGHUXX.S_KAIHUHM;
            this.txtKaiHuYH.Text = this._YS_YG_YONGHUXX.S_KAIHUYH;
            this.txtLianXiBM.Text = this._YS_YG_YONGHUXX.S_LIANXIBM;
            this.txtLianXiDH.Text = this._YS_YG_YONGHUXX.S_LIANXIDH;
            this.txtLianXiR.Text = this._YS_YG_YONGHUXX.S_LIANXIR;
            this.txtShiKaoHY.Text = this._YS_YG_YONGHUXX.I_SHIKAOHY.ToString();
            this.txtYHZH.Text = this._YS_YG_YONGHUXX.S_YINHANGZH;
            this.txtYongHuDZ.Text = this._YS_YG_YONGHUXX.S_DIZHI;
            this.txtBeiZhu.Text = this._YS_YG_YONGHUXX.S_BEIZHU;
            this.txtYongHuH.Text = this._YS_YG_YONGHUXX.S_YONGHUH;
            this.txtYONGHUM.Text = this._YS_YG_YONGHUXX.S_YONGHUM;
            this.txtYouBian.Text = this._YS_YG_YONGHUXX.S_YOUBIAN;
            this.txtYSJ.Text = ((decimal)this._YS_YG_YONGHUXX.N_YSJ).ToString("0.00");
            //获取用户水表数
            DataTable dtTemp = _spHelper.P_YS_GETSHUIBIAOCOUNT(this.txtYongHuH.Text, (int)eI_LEIXING.CurrentMonth).Tables[0];
            this.txtZiLaiSBS.Text = dtTemp.Rows[0][0].ToString();
            this.txtHuiGuanSBS.Text = dtTemp.Rows[0][1].ToString();
            this.txtZiLaiSBS.Text = this.txtZiLaiSBS.Text == "" ? "0" : this.txtZiLaiSBS.Text;
            this.txtHuiGuanSBS.Text = this.txtHuiGuanSBS.Text == "" ? "0" : this.txtHuiGuanSBS.Text;
            //加载各种下拉框
            this.cmbJu.Value = this._YS_YG_YONGHUXX.S_JUBIANH;
            this.txtJu.Text = Convert.ToString(this.cmbJu.Value);
            PageTools.LoadComboxGongSi((DevExpress.Web.ASPxComboBox)this.cmbGongSi, Convert.ToString(this.cmbJu.Value), null);
            this.cmbGongSi.Value = this._YS_YG_YONGHUXX.S_GONGSIBH;
            this.txtGongSi.Text = Convert.ToString(this.cmbGongSi.Value);
            this.cmbGuanLiK.Value = this._YS_YG_YONGHUXX.S_GUANLIKBH;
            this.txtGuanLiK.Text = Convert.ToString(this.cmbGuanLiK.Value);
            this.cmbKaoHeFY.Value = this._YS_YG_YONGHUXX.I_KAOHEFY.ToString();
            this.cmbSheShuiDXDM.Value = this._YS_YG_YONGHUXX.S_SHESHUIDXDM;
            this.cmbXingZhengQ.Value = this._YS_YG_YONGHUXX.S_XINGZHENGQBH;
            this.txtXingZhengQ.Text = Convert.ToString(this.cmbXingZhengQ.Value);
            this.cmbYeWuY.Value = this._YS_YG_YONGHUXX.S_YEWUY;
            this.txtYeWuY.Text = Convert.ToString(this.cmbYeWuY.Value);
            PageTools.LoadComboxYongShuiXZByGuanLiK(this.cmbYongShuiXZ, Convert.ToString(this.cmbGuanLiK.Value), "-", null);
            this.cmbYongShuiXZ.Value = this._YS_YG_YONGHUXX.S_YONGSHUIXZ;
            this.cbTuoShou.Checked = this._YS_YG_YONGHUXX.I_SHOUFEIFS == 1;
            this.cbChengNuo.Checked = this._YS_YG_YONGHUXX.I_CHENNUOFF==1;
            //设置扩展信息
            DataRowCollection drcT = _spHelper.P_YSYG_GETEXTENDINFO(this._YS_YG_YONGHUXX.S_YONGHUH).Tables[0].Rows;
            if(drcT.Count>1)
            {
                throw new Exception("该用户扩展信息数不正确。请检查数据");
            }
            else if (drcT.Count == 1)
            { 
                this.txtFaRen.Text=Convert.ToString(drcT[0]["S_FAREN"]);
                this.cmbZhengJianLX.Value = Convert.ToString(drcT[0]["I_ZHENGJIANLX"]);
                this.txtZhengJianH.Text = Convert.ToString(drcT[0]["S_ZHENGJIANH"]);
                this.cmbDaiMaLX.Value = Convert.ToString(drcT[0]["I_DAIMALX"]);
                this.txtDaiMa.Text = Convert.ToString(drcT[0]["S_JIGOUDM"]);
            }
        }

        /// <summary>
        /// 保存验证
        /// </summary>
        /// <returns></returns>
        private bool ValidateData()
        {
            //获取修改的下一月数据
            DataTable dt = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("I_JLZT=0 and I_LEIXING=1 and S_YONGHUH='{0}'", this.txtYongHuH.Text), null);
            if(dt.Rows.Count!=1)
            {
                PageTools.AlertMsg(this, "该用户无下月数据,请检查数据错误问题！");
                this.txtConYongHuH.Focus();
                return false;
            }
            this.YONGHUXXID = Convert.ToInt32(dt.Rows[0]["ID"]);
            this._YS_YG_YONGHUXX = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXX(this.YONGHUXXID);
            if(this.txtGuanLiK.Text=="")
            {
                PageTools.AlertMsg(this, "请选择管理块！");
                this.cmbGuanLiK.Focus();
                return false;
            }
            //判断用户号合法性
            if (this.txtYongHuH.Text.Substring(0, 2) != this.txtGuanLiK.Text)
            {
                PageTools.AlertMsg(this,"用户号前两位必需与管理块号一致！");
                this.txtYongHuH.Focus();
                return false;
            }
            if (this.txtXingZhengQ.Text == "")
            {
                PageTools.AlertMsg(this, "请选择行政区！");
                this.cmbXingZhengQ.Focus();
                return false;
            }
            if (this.txtYeWuY.Text == "")
            {
                PageTools.AlertMsg(this, "请选择业务员！");
                this.cmbYeWuY.Focus();
                return false;
            }
            if (this.txtYONGHUM.Text == "")
            {
                PageTools.AlertMsg(this, "用户名不能为空！");
                this.txtYONGHUM.Focus();
                return false;
            }
            if (this.txtYongHuDZ.Text == "")
            {
                PageTools.AlertMsg(this, "用户地址不能为空！");
                this.txtYongHuDZ.Focus();
                return false;
            }
            if (this.txtYouBian.Text == "")
            {
                PageTools.AlertMsg(this, "邮编不能为空！");
                this.txtYouBian.Focus();
                return false;
            }
            if (this.cmbYongShuiXZ.Text == "")
            {
                PageTools.AlertMsg(this, "用水性质不能为空！");
                this.cmbYongShuiXZ.Focus();
                return false;
            }
            if (this.txtYSJ.Text == "")
            {
                PageTools.AlertMsg(this, "用水价不能为空！");
                this.txtYSJ.Focus();
                return false;
            }
            if (!PageTools.ValidateString(this.txtYSJ.Text,PageTools.eValidateType.水价))
            {
                PageTools.AlertMsg(this, "请输入正确的用水价！");
                this.txtYSJ.Focus();
                return false;
            }
           
            //如果为托收,需要填写银行账号,开户银行,开户户名
            if (this.cbTuoShou.Checked)
            {
                if (this.txtYHZH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "银行账号不能为空！");
                    this.txtYHZH.Focus();
                    return false;
                }
                if (!PageTools.ValidateString(this.txtYHZH.Text, PageTools.eValidateType.数字))
                {
                    PageTools.AlertMsg(this, "请输入数字类型！");
                    this.txtYHZH.Focus();
                    return false;
                }
                if (this.txtKaiHuYH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "开户银行不能为空！");
                    this.txtKaiHuYH.Focus();
                    return false;
                }
                if (this.txtKaiHuHM.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "开户户名不能为空！");
                    this.txtKaiHuHM.Focus();
                    return false;
                }
            }
            return true;
        }

        #endregion

        
    }
}